package com.liu.controller;

import com.liu.Model.Book;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.ArrayList;
import java.util.List;

@Controller
public class BookController {
@RequestMapping("/books")
public ModelAndView toBookIndex(){
    Book b1 =new Book();
    b1.setId(1);
    b1.setAuthor("罗贯中");
    b1.setName("三国演义");
    Book b2 = new Book();
    b2.setId(2);
    b2.setAuthor("王松");
    b2.setName("springboot开发实战");

    List<Book> books =new ArrayList<>();
    books.add(b1);
    books.add(b2);
    ModelAndView mv = new ModelAndView();
    mv.addObject("books",books);
    mv.setViewName("BookIndex");
    return mv;
}
}
